package com.cradom.event.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cradom.event.model.Time;
import com.cradom.event.service.TimeService;
import com.cradom.event.utils.JsonUtil;

@Controller
public class TimeController {
	
	@Resource
	private TimeService timeService;
	
	/**
	 * 获取各个时间节点，转换为json写到页面中
	 * @param id
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping("/time")
	public void getNodeTime(String id,HttpServletRequest request, HttpServletResponse response) throws IOException{
		Time time=timeService.getNodeTime(id);
		request.setCharacterEncoding("utf-8");  //这里不设置编码会有乱码
        response.setContentType("text/html;charset=utf-8");
        response.setHeader("Cache-Control", "no-cache"); 
        PrintWriter out = response.getWriter();  //输出中文，这一句一定要放到后面，否则中文返回到页面是乱码  
        List<Time> timeList=new ArrayList<Time>();
        timeList.add(time);
        JsonUtil<Time> jsonTime=new JsonUtil<Time>();
        out.print(jsonTime.arrayListToJson(timeList));
	}
}
